<?php
/**
 * Created by PhpStorm.
 * User: xiaomeng
 * Date: 17-9-14
 * Time: 下午3:39
 */

namespace app\websocket\controller;

use swf\common\Bet;
use swf\core\Controller;

class Betting extends Controller
{
    private $bet = null;

    public function __construct()
    {
        $this->bet = new Bet();
    }

    /**
     * 获取趣币余额
     * @param $userId
     * @return mixed
     */
    public function balance()
    {
        $this->server->task(json_encode(['cmd'=>'balance','data'=>['fd'=>$this->frame->fd]]));
        return true;
    }

    /**
     * 投注
     */
    public function bet()
    {
        $allow_params = ['amount','betting_num'];
        $reqData = $this->reqData;//
        //判断数据
        if(array_intersect(array_keys($reqData),$allow_params) != $allow_params)
        {
            $this->send('error',[],10);
        }
        //进入task任务
        $data = [
            'amount'=>$reqData['amount'],
            'betting_num'=>$reqData['betting_num'],
            'fd'=>$this->frame->fd,
        ];
        $this->server->task(json_encode(['cmd'=>'bet','data'=>$data]));
        return;

    }

    /**
     * 投注撤销
     */
    public function betRefund()
    {
        //进入task任务
        $data = [
            'fd'=>$this->frame->fd,
        ];
        $this->server->task(json_encode(['cmd'=>'betRefund','data'=>$data]));
        return;

    }


}